home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / misc / emu / ATUtilities.lha / ATUtilities / tr.c-mit_cache < prev    next >
Text File  |  2000-09-26  |  38KB  |  1,538 lines

  1. /* ******************************************************************* */
  2. /* **                                                               ** */
  3. /* **                     ATUtilities Disk Transfer                 ** */
  4. /* **            Copright (C) 1992-1993 by Thomas Dreibholz         ** */
  5. /* **                      All rights reserved                      ** */
  6. /* **                                                               ** */
  7. /* ******************************************************************* */
  8.  
  9. #include <devices/trackdisk.h>
  10. #include "janus.h"
  11. #include "ATUtilities.h"
  12.  
  13. #define REGISTER_NOPROGS
  14. #include "register.h"
  15.  
  16. #define BIT15 (1<<15)
  17.  
  18. struct UDevice
  19. {
  20.  UBYTE              Name[100];
  21.  UWORD              Unit;
  22.  ULONG              Heads;
  23.  ULONG              SectorsPerTrack;
  24.  ULONG              Tracks;
  25.  UWORD              Motor;
  26.  BOOL               File;
  27. };
  28.  
  29. struct CacheBlock
  30. {
  31.  ULONG  Offset;
  32.  UWORD  Length;
  33.  UBYTE *Memory;
  34.  UBYTE *NextCacheBlock;
  35. };
  36.  
  37. struct TDevice
  38. {
  39.  BOOL               Valid;
  40.  ULONG              Changes;
  41.  struct FileHandle *FileHandle;
  42.  struct IOStdReq   *Request;
  43.  struct MsgPort    *Port;
  44.  LONG               Device;
  45.  struct CacheBlock *FirstCacheBlock;
  46.  struct Remember   *CacheRemember;
  47. };
  48.  
  49. struct UDevice ud[6]=
  50. {
  51.  "trackdisk.device",0,2,11,80,4,FALSE,
  52.  "trackdisk.device",1,2,11,80,4,FALSE,
  53.  "trackdisk.device",0,1,11,80,4,FALSE,
  54.  "trackdisk.device",1,1,11,80,4,FALSE,
  55.  "DH0:Trashcan/File01",0,2,11,80,0,TRUE,
  56.  "DH0:Trashcan/File02",0,4,16,200,0,TRUE
  57. };
  58.  
  59. struct TDevice td[6]=
  60. {
  61.  TRUE,10000000L,NULL,NULL,NULL,-1L,0L,0L,
  62.  TRUE,10000000L,NULL,NULL,NULL,-1L,0L,0L,
  63.  TRUE,10000000L,NULL,NULL,NULL,-1L,0L,0L,
  64.  TRUE,10000000L,NULL,NULL,NULL,-1L,0L,0L,
  65.  TRUE,10000000L,NULL,NULL,NULL,-1L,0L,0L,
  66.  TRUE,10000000L,NULL,NULL,NULL,-1L,0L,0L,
  67. };
  68.  
  69. UWORD Active;
  70. UWORD MotorCNT[6]={0,0,0,0,0,0};
  71.  
  72. UBYTE *TransferPort="ATUtilities Disk Transfer";
  73. UBYTE *PrefsName="AT:Prefs/DiskTransfer.prefs";
  74. UBYTE *HelpName="AT:Help/DiskTransfer.help";
  75.  
  76. LONG  JanusSignal;
  77. LONG  PortSignal;
  78. LONG  TaskSignal;
  79. ULONG JanusSignalMask;
  80. ULONG PortSignalMask;
  81. ULONG WaitSignalMask;
  82. ULONG TaskSignalMask;
  83. ULONG AppSignalMask;
  84. ULONG Signale;
  85.  
  86. struct JanusBase *JanusBase;
  87. struct Library   *GfxBase;
  88. struct Library   *IntuitionBase;
  89. struct Library   *ATUtilitiesBase;
  90.  
  91. struct Process      *MotorTask;
  92. struct Task         *MainTask;
  93. struct MsgPort      *TaskPort,*ReplyPort;
  94. struct ExtSetupSig  *ExtSetupSig;
  95. struct Window       *WindowPtr;
  96. struct RastPort     *rp;
  97. struct CommMemory   *jhbyte,*jhword;
  98. struct AppManager   *app;
  99. struct Message       Message;
  100. struct Message      *AppMessage;
  101.  
  102. #ifdef SHAREWARE
  103. VOID RegCheck();
  104. #endif
  105. VOID HandleInt();
  106. VOID WriteCache();
  107. VOID ShowInfo();
  108. VOID Motor();
  109. VOID EditiereLW();
  110. VOID ZeigeLW();
  111. BOOL EinstellungenAendern();
  112. BOOL AddCache();
  113. VOID InstallAll();
  114. VOID UninstallAll();
  115. VOID InstallFile();
  116. VOID UninstallFile();
  117. VOID InstallDevice();
  118. VOID UninstallDevice();
  119. VOID OpenAll();
  120. VOID CloseAll();
  121. VOID Bearbeite();
  122. VOID BearbeiteFile();
  123. WORD ChangeCheck();
  124. VOID CalcFAT();
  125. VOID MotorOnOff();
  126. VOID Format();
  127. VOID Kopiere();
  128.  
  129. UBYTE           *mem;
  130. struct MsgPort  *Port;
  131.  
  132.  
  133. /* Installationsroutine */
  134. VOID main()
  135. {
  136.  REGISTER UWORD i;
  137.  REGISTER BOOL  bool;
  138.  
  139.  OpenAll();
  140.  bool=FALSE;
  141.  while(bool==FALSE)
  142.   {
  143.    Signale=Wait(WaitSignalMask);
  144.    if(Signale & PortSignalMask)
  145.     {
  146.      i=Received(Port);
  147.      switch(i)
  148.       {
  149.        case UTILITY_CALL:
  150.          bool=EinstellungenAendern();
  151.         break;
  152.        case UTILITY_QUIT:
  153.          bool=ExitWarning();
  154.         break;
  155.        case UTILITY_INFO:
  156.          ShowInfo();
  157.         break;
  158.        case UTILITY_HELP:
  159.          Help(HelpName,0);
  160.         break;
  161.       }
  162.     }
  163.    if(Signale & JanusSignalMask)
  164.     {
  165.      HandleInt();
  166.     }
  167.    if(Signale & TaskSignalMask)
  168.     {
  169.      for(i=0;i<6;i++)
  170.       {
  171.        if(MotorCNT[i]>0)
  172.         {
  173.          MotorCNT[i]--;
  174.          if(MotorCNT[i]==0)
  175.           {
  176.            WriteCache(i);
  177.            MotorOnOff(i,0);
  178.           }
  179.         }
  180.       }
  181.     }
  182.    if(app!=NULL)
  183.     {
  184.      if(Signale & AppSignalMask)
  185.       {
  186.        AppMessage=GetMsg(app->Port);
  187.        if(AppMessage!=NULL)
  188.         {
  189.          ReplyMsg(AppMessage);
  190.          bool=EinstellungenAendern();
  191.         }
  192.       }
  193.     }
  194.   }
  195.  CloseAll();
  196. }
  197.  
  198.  
  199. /* PC-Befehle ausführen */
  200. VOID HandleInt()
  201. {
  202.  REGISTER BOOL  bool;
  203.  REGISTER UWORD i,l;
  204.  REGISTER ULONG o;
  205.  
  206.  switch(jhword->Arg1)
  207.   {
  208.    case 1:
  209.      if(ud[Active].File==FALSE)
  210.       {
  211.        l=jhword->Arg2*512;
  212.        o=jhword->Arg3*512;
  213.        bool=AddCache(&jhword->Memory,o,l);
  214.        if(bool==FALSE)
  215.         {
  216.          WriteCache(Active);
  217.          MotorCNT[Active]=ud[Active].Motor;
  218.          td[Active].Request->io_Data=mem;
  219.          CopyMemQuick(&jhword->Memory,mem,l);
  220.          td[Active].Request->io_Data=mem;
  221.          td[Active].Request->io_Length=l;
  222.          td[Active].Request->io_Offset=o;
  223.          td[Active].Request->io_Command=CMD_WRITE;
  224.          i=DoIO(td[Active].Request);
  225.          if(i!=0)
  226.           {
  227.            switch(i)
  228.             {
  229.              case 28:
  230.                jhword->Arg2=0+BIT15;
  231.               break;
  232.              case 29:
  233.                jhword->Arg2=15+BIT15;
  234.               break;
  235.              default:
  236.                jhword->Arg2=10+BIT15;
  237.               break;
  238.             }
  239.           }
  240.          else
  241.           {
  242.            jhword->Arg2=0;
  243.           }
  244.          td[Active].Request->io_Command=CMD_UPDATE;
  245.          i=DoIO(td[Active].Request);
  246.          if(i!=0)
  247.           {
  248.            switch(i)
  249.             {
  250.              case 28:
  251.                jhword->Arg2=0+BIT15;
  252.               break;
  253.              case 29:
  254.                jhword->Arg2=15+BIT15;
  255.               break;
  256.              default:
  257.                jhword->Arg2=10+BIT15;
  258.               break;
  259.             }
  260.           }
  261.          else
  262.           {
  263.            jhword->Arg2=0;
  264.           }
  265.         }
  266.       }
  267.      else
  268.       {
  269.        l=jhword->Arg2*512;
  270.        Seek(td[Active].FileHandle,jhword->Arg3*512,OFFSET_BEGINNING);
  271.        i=Write(td[Active].FileHandle,&jhword->Memory,l);
  272.        if(i==l)
  273.         {
  274.          jhword->Arg2=0;
  275.         }
  276.        else
  277.         {
  278.          jhword->Arg2=10+BIT15;
  279.         }
  280.       }
  281.     break;
  282.    case 2:
  283.      if(ud[Active].File==FALSE)
  284.       {
  285.        WriteCache(Active);
  286.        MotorCNT[Active]=ud[Active].Motor;
  287.        td[Active].Request->io_Data=mem;
  288.        l=jhword->Arg2*512;
  289.        td[Active].Request->io_Length=l;
  290.        td[Active].Request->io_Offset=jhword->Arg3*512;
  291.        td[Active].Request->io_Command=CMD_READ;
  292.        i=DoIO(td[Active].Request);
  293.        if(i!=0)
  294.         {
  295.          switch(i)
  296.           {
  297.            case 29:
  298.              jhword->Arg2=15+BIT15;
  299.             break;
  300.            default:
  301.              jhword->Arg2=11+BIT15;
  302.             break;
  303.           }
  304.         }
  305.        else
  306.         {
  307.          CopyMemQuick(mem,&jhword->Memory,l);
  308.          jhword->Arg2=0;
  309.         }
  310.       }
  311.      else
  312.       {
  313.        l=jhword->Arg2*512;
  314.        Seek(td[Active].FileHandle,jhword->Arg3*512,OFFSET_BEGINNING);
  315.        i=Read(td[Active].FileHandle,&jhword->Memory,l);
  316.        if(i==l)
  317.         {
  318.          jhword->Arg2=0;
  319.         }
  320.        else
  321.         {
  322.          jhword->Arg2=15+BIT15;
  323.         }
  324.       }
  325.     break;
  326.    case 3:
  327.      jhword->Arg2=0;
  328.     break;
  329.    case 4:
  330.      if(ud[Active].File==FALSE)
  331.       {
  332.        jhword->Arg2=ChangeCheck(Active);
  333.       }
  334.      else
  335.       {
  336.        jhword->Arg2=1;
  337.       }
  338.     break;
  339.    case 5:
  340.      jhword->Arg2=ud[Active].Tracks*ud[Active].Heads*ud[Active].SectorsPerTrack;
  341.      jhword->Arg3=ud[Active].Tracks;
  342.      jhword->Arg4=ud[Active].Heads;
  343.      CalcFAT(Active);
  344.      if(ud[Active].File==FALSE) jhword->Arg7=0; else jhword->Arg7=1;
  345.     break;
  346.    case 6:
  347.      for(i=0;i<6;i++)
  348.       {
  349.        MotorOnOff(i,1);
  350.        MotorCNT[i]=ud[i].Motor;
  351.       }
  352.     break;
  353.    case 10:
  354.      Format();
  355.     break;
  356.    case 20:
  357.      Kopiere();
  358.     break;
  359.    case 100:
  360.      if(td[jhword->Arg2].Valid==FALSE)
  361.       {
  362.        jhword->Arg2=2+BIT15;
  363.       }
  364.      else
  365.       {
  366.        Active=jhword->Arg2;
  367.        jhword->Arg2=0;
  368.       }
  369.     break;
  370.    default:
  371.     break;
  372.   }
  373.  SendJanusInt(29);
  374. }
  375.  
  376.  
  377. /* Diskettenwechsel prüfen */
  378. WORD ChangeCheck(num)
  379.  UWORD num;
  380. {
  381.  REGISTER LONG i;
  382.  
  383.  td[num].Request->io_Command=TD_CHANGENUM;
  384.  DoIO(td[num].Request);
  385.  i=td[num].Request->io_Actual;
  386.  if(i!=td[num].Changes)
  387.   {
  388.    td[num].Changes=i;
  389.    return(0xFF);
  390.   }
  391.  return(1);
  392. }
  393.  
  394.  
  395. /* Laufwerke öffnen */
  396. VOID InstallAll()
  397. {
  398.  REGISTER LONG i;
  399.  
  400.  for(i=0;i<6;i++)
  401.   {
  402.    if(ud[i].File==FALSE)
  403.     {
  404.      InstallDevice(i);
  405.     }
  406.    else
  407.     {
  408.      InstallFile(i);
  409.     }
  410.   }
  411. }
  412.  
  413.  
  414. /* Laufwerke schließen */
  415. VOID UninstallAll()
  416. {
  417.  REGISTER LONG i;
  418.  
  419.  for(i=0;i<6;i++)
  420.   {
  421.    if(ud[i].File==FALSE)
  422.     {
  423.      UninstallDevice(i);
  424.     }
  425.    else
  426.     {
  427.      UninstallFile(i);
  428.     }
  429.   }
  430. }
  431.  
  432.  
  433. VOID InstallDevice(num)
  434.  UWORD num;
  435. {
  436.  
  437.  td[num].Port=CreatePort(0L,0L);
  438.  if(td[num].Port!=NULL)
  439.   {
  440.    td[num].Request=CreateExtIO(td[num].Port,200);
  441.    if(td[num].Request!=NULL)
  442.     {
  443.      td[num].Device=OpenDevice(&ud[num].Name,ud[num].Unit,td[num].Request,0);
  444.      if(td[num].Device!=0)
  445.       {
  446.        UninstallDevice(num);
  447.       }
  448.     }
  449.    else
  450.     {
  451.      UninstallDevice(num);
  452.     }
  453.   }
  454.  else
  455.   {
  456.    UninstallDevice(num);
  457.   }
  458. }
  459.  
  460.  
  461. VOID UninstallDevice(num)
  462.  UWORD num;
  463. {
  464.  
  465.  if(td[num].Valid==TRUE)
  466.   {
  467.    if(td[num].Device==0L) CloseDevice(td[num].Request);
  468.    if(td[num].Request) DeleteExtIO(td[num].Request);
  469.    if(td[num].Port) DeletePort(td[num].Port);
  470.    td[num].Valid=FALSE;
  471.   }
  472. }
  473.  
  474.  
  475. /* Datei installieren */
  476. VOID InstallFile(num)
  477.  UWORD num;
  478. {
  479.  REGISTER ULONG            i,j;
  480.  register struct FileLock *lock;
  481.  
  482.  td[num].Valid=FALSE;
  483.  lock=Lock(&ud[num].Name,ACCESS_READ);
  484.  if(lock!=NULL)
  485.   {
  486.    UnLock(lock);
  487.    td[num].FileHandle=Open(&ud[num].Name,MODE_READWRITE);
  488.    if(td[num].FileHandle!=NULL)
  489.     {
  490.      Seek(td[num].FileHandle,0,OFFSET_END);
  491.      i=Seek(td[num].FileHandle,0,OFFSET_BEGINNING);
  492.      j=512L*(ULONG)ud[num].Tracks*(ULONG)ud[num].Heads*(ULONG)ud[num].SectorsPerTrack;
  493.      if(i!=j)
  494.       {
  495.        MultiRequest("Inkompatible Dateilänge bei LW-Datei",&ud[num].Name,"Okay",NULL);
  496.        Close(td[num].FileHandle);
  497.       }
  498.      else
  499.       {
  500.        td[num].Valid=TRUE;
  501.       }
  502.     }
  503.   }
  504. }
  505.  
  506.  
  507. VOID UninstallFile(num)
  508.  UWORD num;
  509. {
  510.  
  511.  if(td[num].Valid==TRUE)
  512.   {
  513.    if(td[num].FileHandle) Close(td[num].FileHandle);
  514.    td[num].Valid=FALSE;
  515.   }
  516. }
  517.  
  518.  
  519. /* Installationsroutine */
  520. VOID OpenAll()
  521. {
  522.  REGISTER UWORD              i;
  523.  register struct MsgPort    *p;
  524.  register struct FileHandle *fh;
  525.  
  526.  ATUtilitiesBase=OpenLibrary("at-utilities.library",0L);
  527.  if(ATUtilitiesBase==NULL)
  528.   {
  529.    printf("Kann ATUtilities-Library nicht öffnen.\n");
  530.    CloseAll();
  531.   }
  532.  
  533.  GfxBase=OpenLibrary("graphics.library",0L);
  534.  IntuitionBase=OpenLibrary("intuition.library",0L);
  535.  if((GfxBase==NULL)||(IntuitionBase==NULL))
  536.   {
  537.    CloseAll();
  538.   }
  539.  
  540.  p=FindPort(TransferPort);
  541.  if(p!=NULL)
  542.   {
  543.    InfoRequest("ATUtilities Disk Transfer ist schon aktiv.");
  544.    CloseAll();
  545.   }
  546.  
  547.  MainTask=FindTask(NULL);
  548.  SetTaskPri(MainTask,10);
  549.  
  550.  JanusBase=OpenLibrary("janus.library",0L);
  551.  if(JanusBase==NULL)
  552.   {
  553.    ErrorRequest(ERROR_JANUS);
  554.    CloseAll();
  555.   }
  556.  
  557.  TaskSignal=AllocSignal(-1L);
  558.  if(TaskSignal==-1L)
  559.   {
  560.    ErrorRequest(ERROR_SIGNAL);
  561.    CloseAll();
  562.   }
  563.  
  564.  Port=CreatePort(TransferPort,0L);
  565.  if(Port==NULL)
  566.   {
  567.    ErrorRequest(ERROR_MPORT);
  568.    CloseAll();
  569.   }
  570.  
  571.  fh=Open(PrefsName,MODE_OLDFILE);
  572.  if(fh!=NULL)
  573.   {
  574.    Read(fh,&ud,sizeof(struct UDevice)*6);
  575.    Close(fh);
  576.   }
  577.  
  578.  InstallAll();
  579.  
  580.  mem=AllocMem(PUBLIC_PAGESIZE,MEMF_CHIP|MEMF_CLEAR|MEMF_PUBLIC);
  581.  if(mem==NULL)
  582.   {
  583.    ErrorRequest(ERROR_ALLOC);
  584.    CloseAll();
  585.   }
  586.  
  587.  ExtSetupSig=CreatePublicHandler(29);
  588.  if(ExtSetupSig==NULL)
  589.   {
  590.    CloseAll();
  591.   }
  592.  
  593.  TaskPort=CreatePort("Disk Transfer Motor Task <Stop>",0L);
  594.  ReplyPort=CreatePort("Disk Transfer <Stop> Reply",0L);
  595.  if((TaskPort==NULL)||(ReplyPort==NULL))
  596.   {
  597.    ErrorRequest(ERROR_PORT);
  598.    CloseAll();
  599.   }
  600.  
  601.  MotorTask=CreateProcess(Motor,500,"Disk Transfer Motor Task",2);
  602.  if(MotorTask==NULL)
  603.   {
  604.    DeletePort(TaskPort);
  605.    InfoRequest("Kann Motor-Task nicht erstellen.\n");
  606.    CloseAll();
  607.   }
  608.  
  609.  app=CreateAppItem("ATUtilities Disk Transfer");
  610.  if(app!=NULL) AppSignalMask=app->SignalMask; else AppSignalMask=0;
  611.  
  612.  jhword=ExtSetupSig->WordAccess;
  613.  jhbyte=ExtSetupSig->ByteAccess;
  614.  PortSignal=Port->mp_SigBit;
  615.  PortSignalMask=(1L<<PortSignal);
  616.  JanusSignal=ExtSetupSig->JanusSignal;
  617.  JanusSignalMask=ExtSetupSig->JanusSignalMask;
  618.  TaskSignalMask=(1L<<TaskSignal);
  619.  WaitSignalMask=PortSignalMask+JanusSignalMask+TaskSignalMask+AppSignalMask;
  620. }
  621.  
  622.  
  623. /* Programmende */
  624. VOID CloseAll()
  625. {
  626.  if(app) DeleteAppItem(app);
  627.  if(MotorTask!=NULL)
  628.   {
  629.    Message.mn_Node.ln_Type=NT_MESSAGE;
  630.    Message.mn_ReplyPort=ReplyPort;
  631.    PutMsg(TaskPort,&Message);
  632.    WaitPort(ReplyPort);
  633.    DeletePort(ReplyPort);
  634.   }
  635.  if(ExtSetupSig) DeletePublicHandler(ExtSetupSig);
  636.  if(mem) FreeMem(mem,PUBLIC_PAGESIZE);
  637.  if(TaskSignal!=-1) FreeSignal(TaskSignal);
  638.  if(Port) DeletePort(Port);
  639.  UninstallAll();
  640.  if(ATUtilitiesBase) CloseLibrary(ATUtilitiesBase);
  641.  if(GfxBase) CloseLibrary(GfxBase);
  642.  if(IntuitionBase) CloseLibrary(IntuitionBase);
  643.  if(JanusBase) CloseLibrary(JanusBase);
  644.  exit(0);
  645. }
  646.  
  647.  
  648. /* Einstellungs-Fenster */
  649. BOOL EinstellungenAendern()
  650. {
  651.  UBYTE                        text[40];
  652.  BOOL                         bool,ende;
  653.  REGISTER ULONG               Class;
  654.  REGISTER WORD                i,j,id;
  655.  register struct Window       *win;
  656.  register struct RastPort     *rp;
  657.  register struct Gadget       *gad;
  658.  register struct IntuiMessage *msg;
  659.  register struct TextFont     *opal;
  660.  
  661. #ifdef SHAREWARE
  662.  RegCheck();
  663. #endif
  664.  win=CreateStdWindow("ATUtilities - Disk Transfer Einstellungen",
  665.                      75,75,450,122,CLOSEWINDOW|GADGETUP,
  666.                      ACTIVATE|WINDOWDEPTH|WINDOWDRAG|WINDOWCLOSE);
  667.  ende=FALSE;
  668.  if(win!=NULL)
  669.   {
  670.    rp=win->RPort;
  671.    opal=GetOpalFont();
  672.    SetFont(rp,opal);
  673.  
  674.    CreateBoolGadget(win,10,15,155,12,"Einstellungen Okay",1);
  675.    CreateBoolGadget(win,170,15,155,12,"Programm beenden",2);
  676.    CreateBoolGadget(win,335,15,50,12,"Info",3);
  677.    CreateBoolGadget(win,390,15,50,12,"Hilfe",4);
  678.    for(i=0,j=10;i<6;i++,j++)
  679.     {
  680.      sprintf(&text,"Laufwerk %ld:",i+1);
  681.      CreateBoolGadget(win,33,35+(i*14),120,12,&text,j);
  682.      CreateBoolGadget(win,10,35+(i*14),20,12,"!",i+100);
  683.      ZeigeLW(rp,i);
  684.     }
  685.  
  686.    bool=FALSE;
  687.    while(bool==FALSE)
  688.     {
  689.      WaitPort(win->UserPort);
  690.      msg=GetMsg(win->UserPort);
  691.      Class=msg->Class;
  692.      gad=msg->IAddress;
  693.      ReplyMsg(msg);
  694.      switch(Class)
  695.       {
  696.        case GADGETUP:
  697.          id=gad->GadgetID;
  698.          switch(id)
  699.           {
  700.            case 1:
  701.              bool=TRUE;
  702.             break;
  703.            case 2:
  704.              ende=TRUE; bool=TRUE;
  705.             break;
  706.            case 3:
  707.              ShowInfo();
  708.             break;
  709.            case 4:
  710.              Help(HelpName,0);
  711.             break;
  712.            default:
  713.              if((id>=10)&&(id<=15))
  714.               {
  715.                j=id-10;
  716.                EditiereLW(j);
  717.                ZeigeLW(rp,j);
  718.               }
  719.              if((id>=100)&&(id<=105))
  720.               {
  721.                j=id-100;
  722.                if(ud[j].File==FALSE)
  723.                 {
  724.                  if(td[j].Valid==TRUE)
  725.                   {
  726.                    Bearbeite(j);
  727.                   }
  728.                  else
  729.                   {
  730.                    MultiRequest("Dieses Device ist nocht nicht verfügbar.",
  731.                                 "Bitte prüfen Sie die Einstellungen.","Okay",0L);
  732.                   }
  733.                 }
  734.                else
  735.                 {
  736.                  BearbeiteFile(j);
  737.                 }
  738.               }
  739.             break;
  740.           }
  741.         break;
  742.        case CLOSEWINDOW:
  743.          bool=TRUE;
  744.         break;
  745.       }
  746.     }
  747.  
  748.    DeleteStdWindow(win);
  749.   }
  750.  if(ende) ende=ExitWarning();
  751.  return(ende);
  752. }
  753.  
  754.  
  755. /* Parameter ändern */
  756. VOID EditiereLW(num)
  757.  UWORD num;
  758. {
  759.  UBYTE                         text[10];
  760.  BOOL                          ende,f;
  761.  ULONG                         a,b,c,d;
  762.  REGISTER ULONG                Class;
  763.  REGISTER WORD                 i,j,id;
  764.  UBYTE                        *bDevice,
  765.                               *bUnit,
  766.                               *bBlocksPerTrack,
  767.                               *bTracks,
  768.                               *bHeads,
  769.                               *bMotor;
  770.  register struct Window       *win;
  771.  register struct RastPort     *rp;
  772.  register struct IntuiMessage *msg;
  773.  register struct TextFont     *opal;
  774.  register struct Gadget       *gad,*isFile;
  775.  struct FileHandle            *fh;
  776.  
  777.  win=CreateStdWindow("Laufwerksparameter editieren",
  778.                      225,90,400,100,CLOSEWINDOW|GADGETUP,
  779.                      ACTIVATE|WINDOWDEPTH|WINDOWDRAG|WINDOWCLOSE);
  780.  ende=FALSE;
  781.  if(win!=NULL)
  782.   {
  783.    rp=win->RPort;
  784.    opal=GetOpalFont();
  785.    SetFont(rp,opal);
  786.  
  787.    CreateBoolGadget(win,10,15,100,12,"Okay",1);
  788.    CreateBoolGadget(win,120,15,100,12,"Abbruch",2);
  789.  
  790.    if(ud[num].File==FALSE)
  791.     {
  792.      isFile=CreateNToggleGadget(win,300,15,80,12,"Als Datei",100);
  793.     }
  794.    else
  795.     {
  796.      isFile=CreateSToggleGadget(win,300,15,80,12,"Als Datei",100);
  797.     }
  798.  
  799.    bDevice=CreateStringGadget(win,120,30,260,10,&ud[num].Name,100,3);
  800.    sprintf(&text,"%ld",ud[num].Unit);
  801.    bUnit=CreateIntegerGadget(win,120,45,60,10,&text,4,4);
  802.    sprintf(&text,"%ld",ud[num].Heads);
  803.    bHeads=CreateIntegerGadget(win,320,45,60,10,&text,5,5);
  804.    sprintf(&text,"%ld",ud[num].Tracks);
  805.    bTracks=CreateIntegerGadget(win,120,57,60,10,&text,7,6);
  806.    sprintf(&text,"%ld",ud[num].SectorsPerTrack);
  807.    bBlocksPerTrack=CreateIntegerGadget(win,320,57,60,10,&text,5,7);
  808.    sprintf(&text,"%ld",ud[num].Motor);
  809.    bMotor=CreateIntegerGadget(win,320,74,60,10,&text,5,8);
  810.  
  811.    WriteText(rp,15,37,"Device/Datei:");
  812.    WriteText(rp,15,52,"Unit:");
  813.    WriteText(rp,220,52,"S/L-Köpfe:");
  814.    WriteText(rp,15,64,"Spuren:");
  815.    WriteText(rp,220,64,"Sekt./Spur:");
  816.    WriteText(rp,15,82,"Motor-Ausschaltzeit nach x Sekunden:");
  817.  
  818.    ende=FALSE;
  819.    while(ende==FALSE)
  820.     {
  821.      WaitPort(win->UserPort);
  822.      msg=GetMsg(win->UserPort);
  823.      Class=msg->Class;
  824.      gad=msg->IAddress;
  825.      ReplyMsg(msg);
  826.      switch(Class)
  827.       {
  828.        case GADGETUP:
  829.          id=gad->GadgetID;
  830.          switch(id)
  831.           {
  832.            case 2:
  833.              ende=TRUE;
  834.             break;
  835.            case 1:
  836.              j=0;
  837.              a=atol(bUnit);
  838.              b=atol(bTracks);
  839.              c=atol(bHeads);
  840.              d=atol(bBlocksPerTrack);
  841.              i=atol(bMotor);
  842.              if(isFile->Flags & SELECTED) f=TRUE; else f=FALSE;
  843.              if(b<2)
  844.               { InfoRequest("Unzulässige Spurenanzahl."); j=1; }
  845.              if(c<1)
  846.               { InfoRequest("Unzulässige S/L-Kopfanzahl."); j++; }
  847.              if(d<2)
  848.               { InfoRequest("Unzulässige Anzahl von Sektoren/Spur."); j++; }
  849.              if(i>180)
  850.               { InfoRequest("Motor-Zeit nicht empfehlenswert (>180s)."); }
  851.              if(j==0)
  852.               {
  853.                if(strcmp(&ud[num].Name,bDevice)) j=1;
  854.                if(ud[num].Unit!=a) j=1;
  855.                if(ud[num].Tracks!=b) j=1;
  856.                if(ud[num].Heads!=c) j=1;
  857.                if(ud[num].SectorsPerTrack!=d) j=1;
  858.                strcpy(&ud[num].Name,bDevice);
  859.                ud[num].Motor=i;
  860.                ud[num].Unit=a;
  861.                ud[num].Tracks=b;
  862.                ud[num].Heads=c;
  863.                ud[num].SectorsPerTrack=d;
  864.                ud[num].File=f;
  865.                if(j==1)
  866.                 {
  867.                  td[num].Valid=FALSE;
  868.                  MultiRequest("Um Probleme mit MS-DOS zu vermeiden, wird",
  869.                               "das Laufwerk erst nach einem Reset aktiv.",
  870.                               "Okay",NULL);
  871.                 }
  872.                fh=Open(PrefsName,MODE_NEWFILE);
  873.                if(fh!=NULL)
  874.                 {
  875.                  Write(fh,&ud,sizeof(struct UDevice)*6);
  876.                  Close(fh);
  877.                 }
  878.                else
  879.                 {
  880.                  InfoRequest("Fehler beim Schreiben der Prefs-Datei.");
  881.                 }
  882.                ende=TRUE;
  883.               }
  884.             break;
  885.           }
  886.         break;
  887.        case CLOSEWINDOW:
  888.          ende=TRUE;
  889.         break;
  890.       }
  891.     }
  892.    DeleteStdWindow(win);
  893.   }
  894. }
  895.  
  896.  
  897. /* Parameter anzeigen */
  898. VOID ZeigeLW(rp,id)
  899.  struct RastPort *rp;
  900.  UWORD            id;
  901. {
  902.  UBYTE          size[20];
  903.  UBYTE          text[30];
  904.  REGISTER ULONG kb;
  905.  
  906.  kb=(ud[id].Heads*ud[id].Tracks*ud[id].SectorsPerTrack*512)/1024;
  907.  if(kb>=10000)
  908.   {
  909.    sprintf(&size,"%ld MB",kb/1024);
  910.   }
  911.  else
  912.   {
  913.    sprintf(&size,"%ld KB",kb);
  914.   }
  915.  if(ud[id].File==FALSE)
  916.   {
  917.    sprintf(&text,"%s  %s  Unit %ld",
  918.                   &size,&ud[id].Name,ud[id].Unit);
  919.   }
  920.  else
  921.   {
  922.    sprintf(&text,"%s  %s",&size,&ud[id].Name);
  923.   }
  924.  WriteText(rp,160,43+(id*14),&text);
  925. }
  926.  
  927.  
  928. /* Device-Laufwerk bearbeiten */
  929. VOID Bearbeite(num)
  930.  UWORD num;
  931. {
  932.  UBYTE                         text[40];
  933.  REGISTER BOOL                 ende,bool;
  934.  REGISTER ULONG                Class;
  935.  REGISTER WORD                 i,j,id;
  936.  register struct Window       *win;
  937.  register struct RastPort     *rp;
  938.  register struct Gadget       *gad;
  939.  register struct IntuiMessage *msg;
  940.  register struct TextFont     *opal;
  941.  register struct Gadget       *verify;
  942.  BOOL                          v;
  943.  ULONG                         BytesPerTrack;
  944.  ULONG                         Track;
  945.  UBYTE                        *FormatMemory;
  946.  
  947.  win=CreateStdWindow("Speichermedium bearbeiten",
  948.                      225,90,300,76,CLOSEWINDOW|GADGETUP,
  949.                      ACTIVATE|WINDOWDEPTH|WINDOWDRAG|WINDOWCLOSE);
  950.  ende=FALSE;
  951.  if(win!=NULL)
  952.   {
  953.    rp=win->RPort;
  954.    opal=GetOpalFont();
  955.    SetFont(rp,opal);
  956.  
  957.    CreateBoolGadget(win,10,12,100,12,"Okay",1);
  958.    CreateBoolGadget(win,10,30,119,12,"Hard-Format",2);
  959.    CreateBoolGadget(win,10,44,172,12,"Prüfe auf Fehler",3);
  960.    verify=CreateSToggleGadget(win,132,30,50,12,"Verify",100);
  961.    DrawNTextBorder(win,10,58,280,12,"Kein Fehler aufgetreten.");
  962.    DrawNTextBorder(win,190,30,100,12,"0");
  963.    DrawNTextBorder(win,190,44,100,12,"0 %");
  964.  
  965.    ende=FALSE;
  966.    while(ende==FALSE)
  967.     {
  968.      WaitPort(win->UserPort);
  969.      msg=GetMsg(win->UserPort);
  970.      Class=msg->Class;
  971.      gad=msg->IAddress;
  972.      ReplyMsg(msg);
  973.      switch(Class)
  974.       {
  975.        case GADGETUP:
  976.          id=gad->GadgetID;
  977.          switch(id)
  978.           {
  979.            case 2:
  980.            case 3:
  981.              DrawCNTextBorder(win,10,58,280,12,"Kein Fehler aufgetreten.");
  982.              if(verify->Flags & SELECTED) v=TRUE; else v=FALSE;
  983.              if(id==3)
  984.               {
  985.                bool=MultiRequest("Wollen Sie den Datenträger auf",
  986.                                  "Fehler überprüfen ?",
  987.                                  "Ja, Prüfen","Nein, Zurück");
  988.               }
  989.              else
  990.               {
  991.                bool=MultiRequest("Hard-Format: Alle Daten werden gelöscht!",
  992.                                  "Sind Sie wirklich sicher ?",
  993.                                  "Ja, Format","NEIN! Zurück");
  994.               }
  995.              if(bool==TRUE)
  996.               {
  997.                MotorCNT[num]=5;
  998.                BytesPerTrack=ud[num].SectorsPerTrack*ud[num].Heads*512;
  999.                FormatMemory=AllocMem(BytesPerTrack,MEMF_CHIP|MEMF_CLEAR|MEMF_PUBLIC);
  1000.                if(FormatMemory!=NULL)
  1001.                 {
  1002.                  SetDrMd(rp,JAM2);
  1003.                  j=0;
  1004.                  for(Track=0;Track<ud[num].Tracks;Track++)
  1005.                   {
  1006.                    sprintf(&text,"   %ld   ",Track);
  1007.                    DrawNTextBorder(win,190,30,100,12,&text);
  1008.                    sprintf(&text,"   %3ld %%   ",((Track*100)/(ud[num].Tracks-1)));
  1009.                    DrawNTextBorder(win,190,44,100,12,&text);
  1010.                    if(ud[num].File==FALSE)
  1011.                     {
  1012.                      if(id==3)
  1013.                       {
  1014.                        td[num].Request->io_Data=FormatMemory;
  1015.                        td[num].Request->io_Length=BytesPerTrack;
  1016.                        td[num].Request->io_Offset=Track*BytesPerTrack;
  1017.                        td[num].Request->io_Command=CMD_READ;
  1018.                        i=DoIO(td[num].Request);
  1019.                        if(i!=0)
  1020.                         {
  1021.                          if(i==29)
  1022.                           {
  1023.                            InfoRequest("Das Medium ist nicht eingelegt.");
  1024.                            Track=ud[num].Tracks;
  1025.                           }
  1026.                          else
  1027.                           {
  1028.                            sprintf(&text,"Fehler #%ld auf Track %ld.",i,Track);
  1029.                            DrawCNTextBorder(win,10,58,280,12,&text);
  1030.                           }
  1031.                          j++;
  1032.                         }
  1033.                       }
  1034.                      else
  1035.                       {
  1036.                        td[num].Request->io_Data=FormatMemory;
  1037.                        td[num].Request->io_Length=BytesPerTrack;
  1038.                        td[num].Request->io_Offset=Track*BytesPerTrack;
  1039.                        td[num].Request->io_Command=TD_FORMAT;
  1040.                        i=DoIO(td[num].Request);
  1041.                        if(i!=0)
  1042.                         {
  1043.                          sprintf(&text,"Format: Fehler #%ld auf Track %ld.",i,Track);
  1044.                          DrawCNTextBorder(win,10,58,280,12,&text);
  1045.                          j++;
  1046.                          if(i==28)
  1047.                           {
  1048.                            InfoRequest("Das Medium ist schreibgeschützt.");
  1049.                            Track=ud[num].Tracks;
  1050.                           }
  1051.                          else if(i==29)
  1052.                           {
  1053.                            InfoRequest("Das Medium ist nicht eingelegt.");
  1054.                            Track=ud[num].Tracks;
  1055.                           }
  1056.                         }
  1057.                        if((v==TRUE)&&(Track<ud[num].Tracks))
  1058.                         {
  1059.                          td[num].Request->io_Data=FormatMemory;
  1060.                          td[num].Request->io_Length=BytesPerTrack;
  1061.                          td[num].Request->io_Offset=Track*BytesPerTrack;
  1062.                          td[num].Request->io_Command=CMD_READ;
  1063.                          i=DoIO(td[num].Request);
  1064.                          if(i!=0)
  1065.                           {
  1066.                            sprintf(&text,"Verify: Fehler #%ld auf Track %ld.",i,Track);
  1067.                            DrawCNTextBorder(win,10,58,280,12,&text);
  1068.                            j++;
  1069.                           }
  1070.                         }
  1071.                       }
  1072.                     }
  1073.                   }
  1074.                  if(j==0)
  1075.                   {
  1076.                    if(id==3) InfoRequest("Der Datenträger ist fehlerfrei.");
  1077.                   }
  1078.                  else
  1079.                   {
  1080.                    if(id==3)
  1081.                     {
  1082.                      sprintf(&text,"%ld Fehler gefunden worden.",j);
  1083.                      MultiRequest("Bei der Überprüfung sind",&text,"Okay",NULL);
  1084.                     }
  1085.                    else
  1086.                     {
  1087.                      sprintf(&text,"%ld Fehler aufgetreten.",j);
  1088.                      MultiRequest("Bei der Formatierung sind",&text,"Okay",NULL);
  1089.                     }
  1090.                   }
  1091.                  FreeMem(FormatMemory,BytesPerTrack);
  1092.                 }
  1093.               }
  1094.             break;
  1095.            case 1:
  1096.              ende=TRUE;
  1097.             break;
  1098.           }
  1099.         break;
  1100.        case CLOSEWINDOW:
  1101.          ende=TRUE;
  1102.         break;
  1103.       }
  1104.     }
  1105.    DeleteStdWindow(win);
  1106.   }
  1107. }
  1108.  
  1109.  
  1110. /* FAT berechnen */
  1111. VOID CalcFAT(num)
  1112.  UWORD num;
  1113. {
  1114.  REGISTER UWORD anz,i;
  1115.  REGISTER ULONG bytes,plus,sek,spc;
  1116.  
  1117.  
  1118.  sek=ud[num].Tracks*ud[num].Heads*ud[num].SectorsPerTrack;
  1119.  if(sek>4096)
  1120.   {
  1121.    bytes=sek*2;       /* FAT 16-Bit */
  1122.   }
  1123.  else
  1124.   {
  1125.    bytes=(sek*3)/2;   /* FAT 12-Bit */
  1126.   }
  1127.  plus=0;
  1128.  anz=0;
  1129.  for(i=0;i<32000;i++)
  1130.   {
  1131.    if(plus>=bytes)
  1132.     {
  1133.      spc=1;
  1134.      if(anz>15)
  1135.       {
  1136.        do
  1137.         {
  1138.          spc=spc*2;
  1139.          anz=anz/2;
  1140.         } while(anz>15);
  1141.       }
  1142.      jhword->Arg5=anz;
  1143.      jhbyte->Arg6=spc;
  1144.      return;
  1145.     }
  1146.    else
  1147.     {
  1148.      plus+=512;
  1149.      anz++;
  1150.     }
  1151.   }
  1152. }
  1153.  
  1154.  
  1155. /* File-Laufwerk bearbeiten */
  1156. VOID BearbeiteFile(num)
  1157.  UWORD num;
  1158. {
  1159.  UBYTE                       text[35];
  1160.  REGISTER BOOL               bool;
  1161.  REGISTER UBYTE             *mem;
  1162.  REGISTER ULONG              i,j,k,l;
  1163.  register struct FileHandle *fh;
  1164.  register struct Window     *win;
  1165.  register struct RastPort   *rp;
  1166.  struct TextFont            *opal;
  1167.  struct IntuiMessage        *msg;
  1168.  
  1169.  if(td[num].Valid==FALSE)
  1170.   {
  1171.    bool=MultiRequest("Es existiert keine Laufwerksdatei.",
  1172.                      "Möchten Sie eine erstellen ?",
  1173.                      "Ja, Erstellen","Nein, Zurück");
  1174.    if(bool==TRUE)
  1175.     {
  1176.      j=512*ud[num].SectorsPerTrack*ud[num].Heads;
  1177.      mem=AllocMem(j,MEMF_CLEAR|MEMF_PUBLIC);
  1178.      if(mem!=NULL)
  1179.       {
  1180.        fh=Open(&ud[num].Name,MODE_NEWFILE);
  1181.        if(fh!=NULL)
  1182.         {
  1183.          win=CreateStdWindow("Laufwerksdatei erstellen",
  1184.                              75,90,300,30,GADGETUP|CLOSEWINDOW,
  1185.                              WINDOWCLOSE|WINDOWDEPTH|ACTIVATE|WINDOWDRAG);
  1186.          if(win!=NULL)
  1187.           {
  1188.            opal=GetOpalFont();
  1189.            rp=win->RPort;
  1190.            SetFont(rp,opal);
  1191.            CreateBoolGadget(win,10,15,120,12,"Stop !",1);
  1192.            bool=FALSE;
  1193.            if(win!=NULL)
  1194.             {
  1195.              for(i=0;i<ud[num].Tracks;i++)
  1196.               {
  1197.                sprintf(&text,"Track %ld von %ld",i,ud[num].Tracks);
  1198.                DrawCNTextBorder(win,140,15,150,12,&text);
  1199.                k=Write(fh,mem,j);
  1200.                if(k!=j)
  1201.                 {
  1202.                  InfoRequest("Schreibfehler!");
  1203.                  i=ud[num].Tracks;
  1204.                  bool=TRUE;
  1205.                 }
  1206.                msg=GetMsg(win->UserPort);
  1207.                if(msg!=NULL)
  1208.                 {
  1209.                  InfoRequest("Stop!");
  1210.                  i=ud[num].Tracks;
  1211.                  bool=TRUE;
  1212.                 }
  1213.               }
  1214.              if(bool==FALSE)
  1215.               {
  1216.                td[num].FileHandle=fh;
  1217.                td[num].Valid=TRUE;
  1218.               }
  1219.              else
  1220.               {
  1221.                Close(fh);
  1222.                DeleteFile(&ud[num].Name);
  1223.               }
  1224.             }
  1225.            DeleteStdWindow(win);
  1226.           }
  1227.          else
  1228.           {
  1229.            Close(fh);
  1230.            DeleteFile(&ud[num].Name);
  1231.            ErrorRequest(ERROR_ALLOC);
  1232.           }
  1233.         }
  1234.        else InfoRequest("Laufwerksdatei läßt sich nicht erstellen.");
  1235.        FreeMem(mem,j);
  1236.       }
  1237.      else ErrorRequest(ERROR_ALLOC);
  1238.     }
  1239.   }
  1240.  else
  1241.   {
  1242.    win=CreateStdWindow("Laufwerksdatei-Information",75,90,300,90,
  1243.                        CLOSEWINDOW|GADGETUP,
  1244.                        WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG|ACTIVATE);
  1245.    if(win!=NULL)
  1246.     {
  1247.      opal=GetOpalFont();
  1248.      rp=win->RPort;
  1249.      SetFont(rp,opal);
  1250.      CreateBoolGadget(win,10,15,120,12,"Okay",1);
  1251.  
  1252.      sprintf(&text,"Spuren: %ld",ud[num].Tracks);
  1253.      DrawNTextBorder(win,10,30,280,12,&text);
  1254.      sprintf(&text,"S/L-Köpfe: %ld",ud[num].Heads);
  1255.      DrawNTextBorder(win,10,45,280,12,&text);
  1256.      sprintf(&text,"Sektoren/Spur: %ld",ud[num].SectorsPerTrack);
  1257.      DrawNTextBorder(win,10,60,280,12,&text);
  1258.      sprintf(&text,"KBytes: %ld",(ud[num].Tracks*ud[num].SectorsPerTrack*ud[num].Heads)/2);
  1259.      DrawNTextBorder(win,10,75,280,12,&text);
  1260.  
  1261.      WaitPort(win->UserPort);
  1262.      DeleteStdWindow(win);
  1263.     }
  1264.   }
  1265. }
  1266.  
  1267.  
  1268. /* Motor-Kontrollprozeß */
  1269. VOID Motor()
  1270. {
  1271.  register struct Message *msg;
  1272.  
  1273.  geta4();
  1274.  do
  1275.   {
  1276.    Delay(50);
  1277.    Signal(MainTask,TaskSignalMask);
  1278.    msg=GetMsg(TaskPort);
  1279.   }
  1280.  while(msg==NULL);
  1281.  DeletePort(TaskPort);
  1282.  ReplyMsg(msg);
  1283.  Exit(0);
  1284. }
  1285.  
  1286.  
  1287. /* Motor ein- und ausschalten */
  1288. VOID MotorOnOff(num,status)
  1289.  UWORD num;
  1290.  UWORD status;
  1291. {
  1292.  
  1293.  if(td[num].Valid==TRUE)
  1294.   {
  1295.    if(ud[num].File==FALSE)
  1296.     {
  1297.      td[num].Request->io_Command=TD_MOTOR;
  1298.      td[num].Request->io_Length=status;
  1299.      DoIO(td[num].Request);
  1300.     }
  1301.   }
  1302. }
  1303.  
  1304.  
  1305. /* Datenträger formatieren */
  1306. VOID Format()
  1307. {
  1308.  REGISTER ULONG  tSize;
  1309.  REGISTER UBYTE *fBuffer;
  1310.  REGISTER UWORD  res,i;
  1311.  
  1312.  res=0;
  1313.  if(ud[Active].File==FALSE)
  1314.   {
  1315.    tSize=512*ud[Active].SectorsPerTrack*ud[Active].Heads;
  1316.    fBuffer=AllocMem(tSize,MEMF_CHIP|MEMF_CLEAR|MEMF_PUBLIC);
  1317.    if(fBuffer!=NULL)
  1318.     {
  1319.      td[Active].Request->io_Data=fBuffer;
  1320.      td[Active].Request->io_Length=tSize;
  1321.      td[Active].Request->io_Offset=jhword->Arg2*tSize;
  1322.      td[Active].Request->io_Command=TD_FORMAT;
  1323.      i=DoIO(td[Active].Request);
  1324.      if(i==0)
  1325.       {
  1326.        if(jhword->Arg3==1)
  1327.         {
  1328.          td[Active].Request->io_Command=CMD_READ;
  1329.          i=DoIO(td[Active].Request);
  1330.          if(i!=0) res=3;
  1331.         }
  1332.       } else res=2;
  1333.      MotorCNT[Active]=ud[Active].Motor;
  1334.      FreeMem(fBuffer,tSize);
  1335.     }
  1336.    else res=1;
  1337.   }
  1338.  jhword->Arg2=res;
  1339. }
  1340.  
  1341.  
  1342. /* Datenträger kopieren */
  1343. VOID Kopiere()
  1344. {
  1345.  REGISTER ULONG  tSize;
  1346.  REGISTER UBYTE *fBuffer;
  1347.  REGISTER UWORD  res,i;
  1348.  
  1349.  res=0;
  1350.  tSize=512*ud[Active].SectorsPerTrack*ud[Active].Heads;
  1351.  fBuffer=AllocMem(tSize,MEMF_CHIP|MEMF_CLEAR|MEMF_PUBLIC);
  1352.  if(fBuffer!=NULL)
  1353.   {
  1354.    if(ud[Active].File==FALSE)
  1355.     {
  1356.      td[Active].Request->io_Data=fBuffer;
  1357.      td[Active].Request->io_Length=tSize;
  1358.      td[Active].Request->io_Offset=jhword->Arg2*tSize;
  1359.      td[Active].Request->io_Command=CMD_READ;
  1360.      i=DoIO(td[Active].Request);
  1361.     }
  1362.    else
  1363.     {
  1364.      Seek(td[Active].FileHandle,jhword->Arg2*tSize,OFFSET_BEGINNING);
  1365.      i=Read(td[Active].FileHandle,fBuffer,tSize);
  1366.      if(i!=tSize) i=1; else i=0;
  1367.     }
  1368.    if(i==0)
  1369.     {
  1370.      if(ud[jhword->Arg3].File==FALSE)
  1371.       {
  1372.        td[jhword->Arg3].Request->io_Data=fBuffer;
  1373.        td[jhword->Arg3].Request->io_Length=tSize;
  1374.        td[jhword->Arg3].Request->io_Offset=jhword->Arg2*tSize;
  1375.        td[jhword->Arg3].Request->io_Command=TD_FORMAT;
  1376.        i=DoIO(td[jhword->Arg3].Request);
  1377.        if(i==0)
  1378.         {
  1379.          if(jhword->Arg4==1)
  1380.           {
  1381.            td[jhword->Arg3].Request->io_Command=CMD_READ;
  1382.            i=DoIO(td[jhword->Arg3].Request);
  1383.            if(i!=0) res=4;
  1384.           }
  1385.         } else res=3;
  1386.       }
  1387.      else
  1388.       {
  1389.        Seek(td[jhword->Arg3].FileHandle,jhword->Arg2*tSize,OFFSET_BEGINNING);
  1390.        i=Write(td[jhword->Arg3].FileHandle,fBuffer,tSize);
  1391.        if(i!=tSize) res=3;
  1392.       }
  1393.     } else res=2;
  1394.    MotorCNT[Active]=ud[Active].Motor;
  1395.    MotorCNT[jhword->Arg3]=ud[jhword->Arg3].Motor;
  1396.    FreeMem(fBuffer,tSize);
  1397.   } else res=1;
  1398.  jhword->Arg2=res;
  1399. }
  1400.  
  1401.  
  1402. /* Information */
  1403. VOID ShowInfo()
  1404. {
  1405.  InformationBox("ATUtilities Disk Transfer - Information",
  1406.                 "$VER: Disk Transfer - Version 4.0",
  1407.                 "Copyright (C) 1993 by",
  1408.                 "Thomas Dreibholz",
  1409.                 "All rights reserved.",
  1410.                 "AT:Icons/Utility");
  1411. }
  1412.  
  1413.  
  1414. #ifdef SHAREWARE
  1415. VOID RegCheck()
  1416. {
  1417.  REGISTER BOOL               bool;
  1418.  REGISTER UWORD              i,j;
  1419.  register struct TextFont   *opal;
  1420.  register struct FileHandle *fh;
  1421.  register struct RastPort   *rp;
  1422.  register struct Window     *RegWindow;
  1423.  
  1424.  bool=FALSE;
  1425.  fh=Open("SYS:PC/ATUtilities/ATUtilities.reg",MODE_OLDFILE);
  1426.  if(fh!=NULL)
  1427.   {
  1428.    Read(fh,&Kunde,sizeof(struct Kunde));
  1429.    Close(fh);
  1430.    i=CHECKSTR(&Kunde.Code,&Kunde.Vorname,CODE_VN,VN1);
  1431.    i+=CHECKSTR(&Kunde.Code,&Kunde.Nachname,CODE_NN,NN1);
  1432.    i+=CHECKSTR(&Kunde.Code,&Kunde.Straße,CODE_ST,ST1);
  1433.    i+=CHECKSTR(&Kunde.Code,&Kunde.Land,CODE_LA,LA1);
  1434.    i+=CHECKSTR(&Kunde.Code,&Kunde.Postleitzahl,CODE_PL,PL1);
  1435.    i+=CHECKSTR(&Kunde.Code,&Kunde.Ort,CODE_OR,OR1);
  1436.    i+=CHECKCODE(&Kunde.Code);
  1437.    if(i==0)
  1438.     {
  1439.      j=GETPRG(Kunde.Code);
  1440.      if(j & PROG_DISKTRANSFER) bool=TRUE;
  1441.     }
  1442.   }
  1443.  if(bool==FALSE)
  1444.   {
  1445.    RegWindow=CreateStdWindow(NULL,75,100,450,72,0L,0L);
  1446.    if(RegWindow!=NULL)
  1447.     {
  1448.      rp=RegWindow->RPort;
  1449.      opal=GetOpalFont();
  1450.      SetFont(rp,opal);
  1451.      SelectStdFPen(rp);
  1452.      WriteText(rp,15,10,"Disk Transfer - Unregistrierte Version");
  1453.      WriteText(rp,15,23,"Dieses Programm ist Shareware! Möchten Sie es");
  1454.      WriteText(rp,15,33,"regelmäßig nutzen, so müssen Sie es registrieren");
  1455.      WriteText(rp,15,43,"lassen! Weitere Informationen dazu finden Sie in");
  1456.      WriteText(rp,15,53,"der Datei \"Registrierung.DOK\" und im Hilfe-");
  1457.      WriteText(rp,15,63,"system unter \"Shareware-Registrierung\".");
  1458.      Delay(500);
  1459.      DeleteStdWindow(RegWindow);
  1460.     }
  1461.   }
  1462. }
  1463. #endif
  1464.  
  1465.  
  1466. BOOL AddCache(block,offset,len)
  1467.  UBYTE *block;
  1468.  ULONG  offset;
  1469.  UWORD  len;
  1470. {
  1471.  REGISTER UBYTE             *copy;
  1472.  register struct CacheBlock *cb,*old;
  1473.  
  1474.  if(td[Active].FirstCacheBlock==NULL)
  1475.   {
  1476.    td[Active].Request->io_Command=TD_PROTSTATUS;
  1477.    DoIO(td[Active].Request);
  1478.    if(td[Active].Request->io_Actual!=0) return(FALSE);
  1479.   }
  1480.  
  1481.  cb=AllocRemember(&(td[Active].CacheRemember),sizeof(struct CacheBlock),MEMF_PUBLIC|MEMF_CLEAR);
  1482.  if(cb==NULL) return(FALSE);
  1483.  copy=AllocRemember(&(td[Active].CacheRemember),len,MEMF_PUBLIC);
  1484.  if(copy==NULL) return(FALSE);
  1485.  
  1486.  cb->Offset=offset;
  1487.  cb->Length=len;
  1488.  cb->Memory=copy;
  1489.  CopyMemQuick(block,copy,len);
  1490.  if(td[Active].FirstCacheBlock==NULL)
  1491.    td[Active].FirstCacheBlock=cb;
  1492.  else
  1493.   {
  1494.    old=td[Active].FirstCacheBlock;
  1495.    if(old->NextCacheBlock!=NULL)
  1496.     {
  1497.      while(old->NextCacheBlock!=NULL)
  1498.       old=old->NextCacheBlock;
  1499.     }
  1500.    old->NextCacheBlock=cb;
  1501.   }
  1502.  
  1503.  MotorCNT[Active]=ud[Active].Motor;
  1504.  if(MotorCNT[Active]==0) MotorCNT[Active]=5;
  1505.  MotorOnOff(Active,1);
  1506.  jhword->Arg2=0;
  1507.  return(TRUE);
  1508. }
  1509.  
  1510.  
  1511. VOID WriteCache(ii)
  1512.  UWORD ii;
  1513. {
  1514.  register struct CacheBlock *cb;
  1515.  
  1516.  if(td[ii].FirstCacheBlock!=NULL)
  1517.   {
  1518.    cb=td[ii].FirstCacheBlock;
  1519.    do
  1520.     {
  1521.      CopyMemQuick(cb->Memory,mem,cb->Length);
  1522.      td[ii].Request->io_Data=mem;
  1523.      td[ii].Request->io_Offset=cb->Offset;
  1524.      td[ii].Request->io_Length=cb->Length;
  1525.      td[ii].Request->io_Command=CMD_WRITE;
  1526.      DoIO(td[ii].Request);
  1527.      cb=cb->NextCacheBlock;
  1528.     } while(cb!=NULL);
  1529.  
  1530.    td[ii].Request->io_Command=CMD_UPDATE;
  1531.    DoIO(td[ii].Request);
  1532.    FreeRemember(&(td[ii].CacheRemember),TRUE);
  1533.    td[ii].CacheRemember=NULL;
  1534.    td[ii].FirstCacheBlock=NULL;
  1535.   }
  1536. }
  1537.  
  1538.